/*
 * @Description:得分
 * @Author: maskMan
 * @LastEditTime: 2024-04-02 14:28:14
 */
const { ccclass, property } = cc._decorator
@ccclass
export default class score extends cc.Component {
  @property(cc.Node)
  goodNode: cc.Node = null
  @property(cc.Node)
  badNode: cc.Node = null
  @property(cc.Label)
  goodStr: cc.Label = null
  @property(cc.Label)
  badStr: cc.Label = null
  score: number
  start() {
    if (this.score > 0) {
      this._runGoodAction()
    } else {
      this._runBadAction()
    }
  }
  _runGoodAction() {
    this.goodStr.string = '+ ' + this.score.toString()
    this.goodNode.active = true
    const seq = cc.sequence(
      cc.scaleTo(0.2, 1.2).easing(cc.easeIn(1)),
      cc.scaleTo(0.3, 1).easing(cc.easeOut(1)),
      cc.delayTime(0.5),
      cc.callFunc(() => {
        this.node.destroy()
      })
    )
    this.goodNode.runAction(seq)
  }
  _runBadAction() {
    this.badStr.string = this.score.toString()
    this.badNode.active = true
    const seq = cc.sequence(
      cc.scaleTo(0.2, 1.2).easing(cc.easeIn(1)),
      cc.scaleTo(0.3, 1).easing(cc.easeOut(1)),
      cc.delayTime(0.5),
      cc.callFunc(() => {
        this.node.destroy()
      })
    )
    this.badNode.runAction(seq)
  }
}
